package com.aaa.controller;

import com.aaa.entity.User;
import com.aaa.service.impl.UserServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("user")
public class UserController {
    @Resource
    UserServiceImpl userService;
    @RequestMapping("list")
    @ResponseBody
    public List<User> list(){
        return userService.list();
    }
    @RequestMapping("save")
    @ResponseBody
    public boolean save(User user){
        return userService.save(user);
    }
    @RequestMapping("update")
    @ResponseBody
    public boolean update(User user){
        return userService.updateById(user);
    }
    @RequestMapping("remove")
    @ResponseBody
    public boolean remove(Integer uid){
        return userService.removeById(uid);
    }
    @RequestMapping("listWrapper")
    @ResponseBody
    public List<User> listWrapper(String username){
        //按条件查询
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq("username",username);
        return userService.list(wrapper);
    }
    @RequestMapping("select")
    @ResponseBody
    public List<User> select(){
        return userService.select();
    }
    @RequestMapping("select2")
    @ResponseBody
    public List<User> select2(String username){
        return userService.select2(username);
    }
//    @RequestMapping("update2")
//    @ResponseBody
//    public int update2(User user){
//        return userService.update2(user);
//    }
}
